<template>
  <div class="app-container">
    <div class="menu_bar">
      <div class="menu_bar-container">
        <div :class="['menu_bar-item', currentTab === 1 ? 'active' : '']" @click="changeTab(1)">专属服务</div>
        <div :class="['menu_bar-item', currentTab === 2 ? 'active' : '']" @click="changeTab(2)">成长计划</div>
        <div :class="['menu_bar-item', currentTab === 3 ? 'active' : '']" @click="changeTab(3)">会员成员</div>
      </div>
    </div>
    <div>
      <div class=" admin">欢迎 admin：</div>
      <div v-if="currentTab===1">
        <div>
          <div class="content-text">VIP用户专属权限说明：</div>
          <div class="content-text">1.优先购物权：VIP客户在商场促销活动或限量商品发售时，享有优先购买权，确保能够抢先购买到心仪的商品。</div>
            <div class="content-text">2.生日福利：在VIP客户生日当天，商场会提供生日礼物、优惠券或额外的折扣，让客户感受到特别的关爱。</div>
              <div class="content-text">3.积分兑换：VIP客户购物时可以累积积分，积分可以在商场内兑换商品、优惠券或参加商场举办的各类活动。</div>
                <div class="content-text">4.专柜导购服务：为VIP客户提供专业的导购人员，根据客户的需求和喜好推荐合适的商品，提供一对一的购物指导。</div>
                  <div class="content-text">5.会员活动：商场会定期举办VIP会员专享的活动，如新品发布会、时尚讲座、手工DIY等，让客户在购物的同时，还能享受到丰富的文化生活。</div>
                    <div class="content-text">6.快速结账通道：在高峰期，VIP客户可以享受到专门的结账通道，避免排队等待，节省购物时间。</div>
        </div>
      </div>
      <div v-else-if="currentTab===2">
        <div class="content-middle">
          <div class="content-left">
            <div class="content-left1">积分累计：</div>
            <div class="content-left2">
              <div class="content-text1">会员等级结算：</div>
              <div class="image-area">
                <div class="image-item"><div class="image-vip"></div><div class="image-text">普通VIP</div></div>
                <div class="image-item marin40"><div class="image-vip "></div><div class="image-text">银卡VIP</div></div>
                  <div class="image-item marin80"><div class="image-vip "></div><div class="image-text">金卡VIP</div></div>
                    <div class="image-item marin80"><div class="image-vip "></div><div class="image-text">白金卡VIP</div></div>
              </div>
            </div>
          </div>
          <div class="content-right">
            VIP成长机制说明：<br>
            1.普通VIP：<br>
            积分累积比例： 1元消费 = 1积分<br>
            生日福利： 生日当天享受额外5%折扣<br>
            专享活动： 定期收到VIP专享活动邀请<br>
            2.银卡VIP<br>
            积分累积比例： 1元消费 = 1.2积分<br>
            生日福利： 生日当天享受额外10%折扣<br>
            专享活动： 定期收到VIP<br>
            专享活动邀请，优先报名权<br>
            专柜导购： 提供专柜导购预约服务<br>
            3.金卡VIP<br>
            积分累积比例： 1元消费 = 1.5积分<br>
            生日福利： 生日当天享受额外15%折扣<br>
            专享活动： 定期收到VIP专享活动邀请，优先报名权，免费参加部分活动<br>
            专柜导购： 提供专柜导购预约服务，享受个性化购物建议<br>
            4.白金卡VIP<br>
            积分累积比例： 1元消费 = 2积分<br>
            生日福利： 生日当天享受额外20%折扣，以及专属生日礼物<br>
            专享活动： 定期收到VIP专享活动邀请，优先报名权，免费参加所有活动<br>
            专柜导购： 提供专柜导购预约服务，享受个性化购物建议和专属试衣服务<br>
            退换货政策： 享受更宽松的退换货政策，延长退换货时间限制<br>
            贵宾休息室： 提供专属贵宾休息室，享受舒适休息空间和茶点服务<br>
          </div>
        </div>
      </div>
      <div v-else>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="客户编号" prop="cusId">
            <el-input
              v-model="queryParams.cusId"
              placeholder="请输入客户编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="VIP会员积分" prop="cusMemberPoints">
            <el-input
              v-model="queryParams.cusMemberPoints"
              placeholder="请输入VIP会员积分"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="VIP会员等级" prop="cusMemberGrades">
            <el-input
              v-model="queryParams.cusMemberGrades"
              placeholder="请输入VIP会员等级"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:data:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:data:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:data:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['system:data:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="客户编号" align="center" prop="cusId" />
          <el-table-column label="VIP会员积分" align="center" prop="cusMemberPoints" />
          <el-table-column label="VIP会员等级" align="center" prop="cusMemberGrades" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:data:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:data:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

        <!-- 添加或修改VIP会员客户对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item label="客户编号" prop="cusId">
              <el-input v-model="form.cusId" placeholder="请输入客户编号" />
            </el-form-item>
            <el-form-item label="VIP会员积分" prop="cusMemberPoints">
              <el-input v-model="form.cusMemberPoints" placeholder="请输入VIP会员积分" />
            </el-form-item>
            <el-form-item label="VIP会员等级" prop="cusMemberGrades">
              <el-input v-model="form.cusMemberGrades" placeholder="请输入VIP会员等级" />
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
      </div>
    </div>

  </div>
</template>

<script>
import { listData, getData, delData, addData, updateData } from "@/api/system/data";

export default {
  name: "Data",
  data() {
    return {
      /// 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // VIP会员客户表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cusId: null,
        cusMemberPoints: null,
        cusMemberGrades: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cusId: [
          { required: true, message: "客户编号不能为空", trigger: "blur" }
        ],
        cusMemberPoints: [
          { required: true, message: "VIP会员积分不能为空", trigger: "blur" }
        ],
        cusMemberGrades: [
          { required: true, message: "VIP会员等级不能为空", trigger: "blur" }
        ]
      },
      currentTab: 1, // 当前tab
    };
  },
  created() {
    this.getList();
  },
  methods: {
    changeTab(currentTab) {
      this.currentTab = currentTab;
    },
    /** 查询VIP会员客户列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cusId: null,
        cusMemberPoints: null,
        cusMemberGrades: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cusId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加VIP会员客户";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const cusId = row.cusId || this.ids
      getData(cusId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改VIP会员客户";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dataId != null) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cusIds = row.cusId || this.ids;
      this.$modal.confirm('是否确认删除VIP会员客户编号为"' + cusIds + '"的数据项？').then(function() {
        return delData(cusIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.menu_bar {
  height: 50px;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.menu_bar-container {
  height: 100%;
  width: 600px;
  display: flex;
}
.menu_bar-item {
  border: 1px solid #1c84c6 ;
  height: 100%;
  flex: 1;
  line-height: 50px;
  text-align: center;
  color: #00afff;
}

.menu_bar-item.active {
  background: #1c84c6;
  color: white;
  font-weight: 500;
}

.content-text {
  font-size:20px;
  color: #5a5e66;
  margin: 40px 0;
}

.content-text1 {
  font-size:20px;
  color: #5a5e66;
  margin-right: 30px;
}

.content-middle {
  display: flex;
  flex-direction: row;
}

.content-left {
  width: 50%;
  display: flex;
  flex-direction: column;
}

.content-left1 {
  height: 100px;
  line-height: 100px;
  width: 200px;
}

.content-left2 {
  height: 100px;
  flex: 1;
  line-height: 100px;
  display: flex;
}

.image-text {
  right: 30px;
  margin-left: 20px;
}

.image-area {
  flex: 1;
}

.image-item {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.content-right {
  width: 50%;
}

.image-vip {
  width: 50px;
  height: 50px;
  background-size: cover;
  background-image: url('../images/vip-fill.png');
}

.admin {
  marin-top: -40px;
  font-size:20px;
  color: #5a5e66;
}

.marin40 {
  margin-top: 40px;
}

.marin80 {
  margin-top: 80px;
}
</style>
